/**
 * 
 */
package com.flymobi.util;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

/**
 * @author Administrator
 * 
 */
public class DoubleConvert extends StrutsTypeConverter {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.struts2.util.StrutsTypeConverter#convertFromString(java.util
	 * .Map, java.lang.String[], java.lang.Class)
	 */
	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
		if (Double.class == arg2) {
			String str = arg1[0];
			if (str.equals("")) {
				str = "0";

			}
			return Double.parseDouble(str);
		} else if (Float.class == arg2) {
			String str = arg1[0];
			if (str.equals("")) {
				str = "0";

			}
			return Float.parseFloat(str);
		} else if (Integer.class == arg2) {
			String str = arg1[0];
			if (str.equals("")) {

				str = "0";
			}
			return Integer.parseInt(str);

		}
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.struts2.util.StrutsTypeConverter#convertToString(java.util
	 * .Map, java.lang.Object)
	 */
	@Override
	public String convertToString(Map arg0, Object arg1) {
		return arg1.toString();
	}

}
